package com.example.wanghao.wangyixinwen.view;

import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Created by wanghao on 2016/5/17.
 */
public class Rotatetransformer  implements ViewPager.PageTransformer{
    private static float ROTATE_MAX = 25f;//旋转的最大角度
    @Override
    public void transformPage(View view, float position) {

        int pageWidth = view.getWidth();//屏幕的宽度
        System.out.println("pageWidth :" +pageWidth);

        if (position < -1) { // [-Infinity,-1)
            view.setRotation(0);//设置为不旋转

        } else if (position <= 0) { //a页面
            //第一个view对象的position[-0,-1] =[0,-1]
            //[0,25]
            view.setRotation(position*ROTATE_MAX);
            view.setPivotX(view.getWidth()/2);
            view.setPivotY(view.getHeight());
        } else if (position <= 1) { //b页面
            //第二个view对象的position[1,0]
            //[25,0]
            view.setRotation(position*ROTATE_MAX);
            view.setPivotX(view.getWidth()/2);
            view.setPivotY(view.getHeight());

        } else { // (1,+Infinity]
            // This page is way off-screen to the right.
            view.setRotation(0);
        }
    }
}
